﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using DataFileApplication_WPF.Models;

namespace DataFileApplication_WPF.Common
{
    public class MenuItemValidConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //treeView
            if (value != null && value is TreeItemStruct tree)
            {
                if (parameter != null)  //添加子节点/添加数组子节点
                {
                    return !tree.IsArray;
                }
                else
                {
                    //禁用Root节点的功能菜单
                    //判断是否为Root节点，Root节点也有父节点 ，若为root节点，则 Parent.Parent == null
                    return tree.Parent.Parent != null;
                }
            }
            //dataGrid
            else if (value != null && value is DataGridItemStruct dataGrid)
            {
                return dataGrid != null;
            }
            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
